package com.kepler.social.web.controller;

import com.kepler.dict.dao.domain.Area;
import com.kepler.love.dao.domain.LoverInfo;
import com.kepler.social.dao.domain.UserBaseInfo;
import com.kepler.social.service.manager.DictManager;
import com.kepler.social.service.manager.LoveManager;
import com.kepler.social.service.manager.UserManager;
import com.kepler.social.core.sharding.DatasourceType;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ms")
public class MsAndPintController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MsAndPintController.class);

    @Autowired
    private UserManager userManager;
    @Autowired
    private LoveManager loveManager;
    @Autowired
    private DictManager dictManager;

    @RequestMapping(value = "/solial/get")
    public UserBaseInfo solial_get(Long id) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setDatabaseShardingValue(DatasourceType.DATASOURCE_SOCAIL.toString());
//            hintManager.setWriteRouteOnly();
            UserBaseInfo userBaseInfo = userManager.getById(id);
            return userBaseInfo;
        }
    }

    @RequestMapping(value = "/dict/get")
    public Area dict_get(Long id) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setDatabaseShardingValue(DatasourceType.DATASOURCE_DICT.toString());
//            hintManager.setWriteRouteOnly();
            Area area = dictManager.getAreaById(id);
            return area;
        }
    }

    @RequestMapping(value = "/love/get")
    public LoverInfo love_get(Long id) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setDatabaseShardingValue(DatasourceType.DATASOURCE_LOVE.toString());
//            hintManager.setWriteRouteOnly();
            LoverInfo lover = loveManager.getLoverById(id);
            return lover;
        }
    }


}
